//
//  UserLoanTableViewCell.m
//  huien
//
//  Created by yiban on 2017/7/19.
//  Copyright © 2017年 lcb. All rights reserved.
//

#import "UserLoanTableViewCell.h"

@interface UserLoanTableViewCell ()
@property(nonatomic,strong)UIButton *rechargeBtn;
@property(nonatomic,strong)UIButton *cashBtn;
@property(nonatomic,strong)UIButton *loanBtn;
@end
@implementation UserLoanTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor =[UIColor clearColor];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    self.data =model;
    self.indexPath=indexPath;
    NSMutableArray *moudles = (NSMutableArray*)model;
    //
    self.rechargeBtn.frame = CGRectMake((SCREEN_WIDTH/2-SCREEN_WIDTH/4)/2, 5, SCREEN_WIDTH/4, 40);
    self.cashBtn.frame = CGRectMake(SCREEN_WIDTH/2+self.rechargeBtn.frame.origin.x, self.rechargeBtn.frame.origin.y, SCREEN_WIDTH/4, 40);
    self.loanBtn.frame = CGRectMake(self.rechargeBtn.frame.origin.x, self.rechargeBtn.frame.origin.y+ self.rechargeBtn.frame.size.height+15, SCREEN_WIDTH-self.rechargeBtn.frame.origin.x*2, 40);
    
    for (ModuleModel *module in moudles) {
        if (module.Id ==1) {
            _rechargeBtn.tag = module.Id;
            [_rechargeBtn setTitle:module.title forState:UIControlStateNormal];
        }else if (module.Id ==2) {
            _cashBtn.tag = module.Id;
            [_cashBtn setTitle:module.title forState:UIControlStateNormal];
        }else if (module.Id ==3) {
            _loanBtn.tag = module.Id;
            [_loanBtn setTitle:module.title forState:UIControlStateNormal];
        }
    }
    
    
}
+(CGFloat)returnCellHeight
{
    return 115;
}
-(void)dealloc
{
    [LcbLog log:@"UserMoneyTableViewCell--------->dealloc"];
}

-(UIButton*)rechargeBtn
{
    if (!_rechargeBtn) {
        _rechargeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _rechargeBtn.tag=1;
        _rechargeBtn.backgroundColor =UIColorFromRGB(0x00a5ed);
        _rechargeBtn.layer.cornerRadius = 40/2;
        _rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_rechargeBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        [_rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
        [_rechargeBtn addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_rechargeBtn];
        [_rechargeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    }
    return _rechargeBtn;
}
-(UIButton*)cashBtn
{
    if (!_cashBtn) {
        _cashBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _cashBtn.tag=2;
        _cashBtn.backgroundColor =UIColorFromRGB(0x00a5ed);
        _cashBtn.layer.cornerRadius = 40/2;
        _cashBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_cashBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        [_cashBtn setTitle:@"提现" forState:UIControlStateNormal];
        [_cashBtn addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cashBtn];
        [_cashBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    }
    return _cashBtn;
}
-(UIButton*)loanBtn
{
    if (!_loanBtn) {
        _loanBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _loanBtn.tag=3;
        _loanBtn.backgroundColor =UIColorFromRGB(0x00a5ed);
        _loanBtn.layer.cornerRadius = 40/2;
        _loanBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_loanBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        [_loanBtn setTitle:@"我要借款" forState:UIControlStateNormal];
        [_loanBtn addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_loanBtn];
        [_loanBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    }
    return _loanBtn;
}

-(void)clickEvent:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    if (self.actionBlock) {
        self.actionBlock(BEventType_Module,self,btn.tag,btn.titleLabel.text,self.indexPath);
    }
}

@end
